package com.batchbrake.main;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class EFile extends File {
	private static final long serialVersionUID = 7739605407712714114L;

	public EFile(String pathname) {
		super(pathname);
	}

	public String getExtension() {
		int index = getName().lastIndexOf(".");
		
		if( index >= 0 ) {
			return getName().substring(index+1);
		} else {
			return null;
		}
	}
	
	public String getBaseName() {
		String ext = getExtension();
		if( ext != null ) {
			return getName().substring(0, getName().length() - ext.length() - 1);
		} else {
			return getName();
		}
	}
	
	public EFile getParentEFile() {
		return new EFile(this.getParent());
	}
	
	public EFile[] listEFiles() {
		if( isDirectory() ) {
			File[] files = listFiles();
			EFile[] efiles = new EFile[files.length];

			for( int i = 0; i < files.length; i++ ) {
				efiles[i] = new EFile(files[i].getAbsolutePath());
			}
			return efiles;
		} else {
			return null;
		}
	}
}
